<?
class ServicecatController extends BaseController{
    var $type;
    var $cat_id;
    var $queryCat;
    var $queryCatType;
    var $title;
    public function __construct($type = '',$serCat = 0){
        parent::__construct();
        global $global_category_config;
        if(!$type){
            $this->type = '';
            $this->queryCatType = '';
        }
        if($type){
            if($type == 'dich-vu-phan-cung'){
                $this->type = 'serviceHardID';
                $this->title = 'Dịch vụ phần cứng';
            }else{
                $this->type = 'serviceSoftID';
                $this->title = 'Dịch vụ phần mềm';
            }
            $this->cat_id = $global_category_config[$this->type];
            $this->queryCatType = 'AND pro_cat_id = '.$this->cat_id.' OR cat_parent_id = '.$this->cat_id;
            
        }
        if($serCat == 0) {
            $this->queryCat = '';
            $this->cat_id = 24;
        }else {
            $this->queryCat = 'AND pro_cat_id = '.$serCat;
            $this->cat_id = $serCat;
            $db_cat = new db_query('SELECT cat_id,cat_name FROM categories_multi WHERE cat_id = '.$serCat);
            $title_cat = mysql_fetch_assoc($db_cat->result);unset($db_cat);
            $this->title = $title_cat['cat_name'];
        }
        $this->seo_string = '<title>'.$this->title.'</title>
                            <meta name="description" content="Các dịch vụ trong danh mục '.$this->title.'" />';
    }
    public function getServiceList(){
        global $global_category_config;
        if($this->type){
            //Lay ra tung loai service
            if($this->type == 'serviceHardID')
                $header = 'Dịch vụ phần cứng';
            if($this->type == 'serviceSoftID')
                $header = 'Dịch vụ phần mềm';
            $db_query = new db_query('SELECT pro_id,pro_name,pro_price,pro_thumb,pro_cat_id,cat_id,cat_parent_id,cat_name
                                      FROM products
                                      INNER JOIN categories_multi ON cat_id = pro_cat_id
                                      WHERE pro_active = 1 '.$this->queryCatType);
            $array_product = array();
            while($row = mysql_fetch_assoc($db_query->result)){
                $tmp = array(
                    'name'=>$row['pro_name'],
                    'price'=>$row['pro_price'],
                    'thumb'=>PATH_PICTURE_PRODUCT_SMALL . $row['pro_thumb'],
                    'url'=>generate_service_detail_url($row)
                );
                $array_product[] = $tmp;
            }
            
            $html = ServicecatLayout::service_list(array('header'=>$header,'list'=>$array_product));
        }else{
            //List cac service ra theo 2 phan dich vu phan cung va dich vu phan mem
            $html = '';
            //Lay ra tung loai service
            //$this->type = 'serviceHardID';
            //$this->cat_id = $global_category_config[$this->type];
            //$header = 'Dịch vụ phần cứng';
            $db_query = new db_query('SELECT pro_id,pro_name,pro_price,pro_thumb,pro_cat_id,cat_id,cat_parent_id,cat_name
                                      FROM products
                                      INNER JOIN categories_multi ON pro_cat_id = cat_id
                                      WHERE pro_active = 1 '.$this->queryCat);
            $array_product = array();
            while($row = mysql_fetch_assoc($db_query->result)){
                $header = $row['cat_name'];
                $tmp = array(
                    'name'=>$row['pro_name'],
                    'price'=>$row['pro_price'],
                    'thumb'=>PATH_PICTURE_PRODUCT_SMALL . $row['pro_thumb'],
                    'url'=>generate_service_detail_url($row)
                );
                $array_product[] = $tmp;
            }
            if(!isset($header)) 
                $header = 'Chưa có dịch vụ';
                
            $html .= ServicecatLayout::service_list(array('header'=>$header,'list'=>$array_product));
            
        }
        return $html;
    }
    public function getBreadCrumb(){
        $html = '';
        if($this->type == 'serviceHardID'){
            $html .= '<div class="breadcrumb">
                        <ul>
                            <li><a href="/">Trang chủ</a></li>
                            <li><a href="'.generate_service_cat('dich-vu-phan-cung').'">Dịch vụ phần cứng</a></li>
                        </ul>
                    </div>';
        }else if($this->type == 'serviceSoftID'){
            $html .= '<div class="breadcrumb">
                        <ul>
                            <li><a href="/">Trang chủ</a></li>
                            <li><a href="'.generate_service_cat('dich-vu-phan-mem').'">Dịch vụ phần mềm</a></li>
                        </ul>
                    </div>';
        }else{
            $db_cat = new db_query('SELECT cat_id,cat_name,cat_parent_id FROM categories_multi WHERE cat_id = '.$this->cat_id);
            $bread = mysql_fetch_assoc($db_cat->result);
            $db_cat_pa = new db_query('SELECT cat_id,cat_name,cat_parent_id FROM categories_multi WHERE cat_id = '.$bread['cat_parent_id']);
            $bread_pa = mysql_fetch_assoc($db_cat_pa->result);
            $html .= '<div class="breadcrumb">
                        <ul>
                            <li><a href="/">Trang chủ</a></li>
                            <li><a href="'.generate_service_cat(removeTitle($bread_pa['cat_name'])).'">'.$bread_pa['cat_name'].'</a></li>
                            <li><a href="'.generate_service_cat(removeTitle($bread['cat_name']),$bread['cat_parent_id'],$this->cat_id).'">'.$bread['cat_name'].'</a></li>
                        </ul>
                    </div>';
        }
        return $html;

    }
}
?>